<?php
require 'PIHandClass.php';
$gameTotelScore = get_post_meta($post->ID, 'GameTotalScore', true);
$gameTotelScoreTimes = get_post_meta($post->ID, 'GameTotalScoreTimes', true);
$siteurl = get_bloginfo('template_url');

//更新游戏的PI值。
$piClass = new PIHandClass();
$piClass->handPostPIByPostId($post->ID);


//浏览次数更新。
setPostViews($post->ID);

get_header();

$user = $_SESSION['userdata'];
?>		

		<script type="text/javascript" > 
			   	$(function(){
			   		get_rate(<?php echo $gameTotelScore ? ($gameTotelScore / $gameTotelScoreTimes) : 0;?>);
			   		$("#sn").html(<?php echo $gameTotelScoreTimes;?>);
			   	});

				function goGame(){
					window.open ('go?gameid=<?php echo $post->ID;?>', 'newwindow', 'height=768, width=1024, top=40, left=40, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no, resizable=0');
				}
			
			   	function up_rate(rate){
			   		$("#big_rate_up").width("0");
			   		$.post("<?php bloginfo('template_url');?>/grandajax.php", {"postid": "<?php echo $post->ID;?>","score":rate}, function(str){
							var strs = str.split(":");
							get_rate(strs[0]);
							$("#sn").html(strs[1]);
			   	   		});
			   	}

			   	function collectGame(){
				   	$.post("<?php bloginfo('template_url');?>/collectAjax.php",{"gameid":"<?php echo $post->ID;?>", "userid":"<?php echo $user->ID;?>"},
						   	function(str){
					   		$("#shoucang").html("成功收藏！");
					   		$("#shoucang").css("color", "green");
				   	});
			   	}

			   <?php if(!$user){?>

			   function collectUnLogin(){
				   loginCallBack = collectGame;
				   opWin("collectLinked");
			   }
				   	
			   	<?php }?>
			   	
		</script>
		<?php
			$gamePic = get_post_meta($post->ID, 'GamePic', true);  
			$gameLink = get_post_meta($post->ID, 'GameLink', true);
			$GameSize = get_post_meta($post->ID, 'GameSize', true);
		?>
<div id="Dleft">		
			<div id="Dlefttop" style="height: 166px;">
			<?php if($user){//$hasCollect = hasCollected($user->ID, $post->ID);echo $hasCollect>0 ? "已收藏" : '[<a href="javascript:void(0)" onclick="collectGame();">添加收藏</a>]';
				}else{?><a href="javascript:void(0)"  onclick="opWin()" ><img alt="添加收藏" src="<?php echo $siteurl ?>/images/shoucang.jpg" id="scimg"></a><?php }?>
				<span id="shoucang"><?php if($user){
					$hasCollect = hasCollected($user->ID, $post->ID);
					echo $hasCollect>0 ? "已收藏" : '[<a href="javascript:void(0)"  onclick="collectGame();">添加收藏</a>]';
				}else{?>[<a id="collectLinked" href="javascript:void(0)"  onclick="collectUnLogin()" >添加收藏</a>]<?php }?></span>
				<!-- add by shiwei 2011-12-07 delay img print -->
				<?php 
					$delayImgId= "delayId".$post->ID ;
					$loadUrl = $siteurl."/images/load.gif";
				?>
				<!-- add end by shiwei -->
				<img id="game_pic" src="<?php echo $gamePic; ?>" onerror="this.src=<?php echo $siteurl?>/images/onerror.jpg" onclick="goGame()" style="cursor: pointer;" alt="<?php echo the_title(); ?>"  title="<?php echo the_title(); ?>" width="137" height="144" />
				 <img id="ganmesrart"   src="<?php bloginfo('template_url');?>/images/zstart.gif" alt="开始游戏" title="开始游戏" onclick="goGame();" style="cursor: pointer;" />
             	 <div id="user_rate">
					 <div id="big_rate_bak">
						 <b rate="1" onclick="javascript:up_rate(10);">&nbsp;</b>
						 <b rate="2" onclick="javascript:up_rate(20);">&nbsp;</b>
						 <b rate="3" onclick="javascript:up_rate(30);">&nbsp;</b>
						 <b rate="4" onclick="javascript:up_rate(40);">&nbsp;</b>
						 <b rate="5" onclick="javascript:up_rate(50);">&nbsp;</b>
						 <div style="width:45px;" id="big_rate_up"></div>
					 </div>
					 <p><span id="s" class="s"></span><span id="g" class="g"></span></p>
				</div>
                <span id="pingfentishi">* 滑动星星点击评分</span>       
				<ul>
					<li><h1 id="D_link"><?php echo the_title(); ?></h1></li>
					<li>游戏大小：<span><?php echo $GameSize  ?></span></li>
					<li><?php $cates = get_the_category();
					$pcats = get_category_parents($cates[0]->term_id); $pcats = explode("/", $pcats);
					if($pcats[0] == "手机游戏") echo "游戏平台"; else echo "游戏分类";?>：<span><?php foreach((get_the_category()) as $category) {echo $category->cat_name ;}?></span></li>
					<li>更新日期：<span id="datespan"><?php echo the_time('Y年n月j日'); ?></span></li>
					<li>游戏评分：</li>
					<li id="gameaddrs">游戏地址：<samp id="gaddr"><?php echo $gameLink  ?></samp></li>  
				</ul>

		  </div>
			<samp id="toupiaonum" >(<span id="sn" class="g" style="float:none;display: inline; color:#DD5400;font-size:18px; "></span> 次评分)</samp>

			<div id="D_left_buttom">
				<p><?php echo $post->post_content  ?>
				</p>
			</div>
			
			
			
			 <div id="fxd">
            	<img src="<?php bloginfo('template_url');?>/images/fxd.gif" width="122" height="83" style="float:left; width:122px;" />
                <div id="fxlist">
                	<ul>
                    	<li>
                    	<a href="javascript:(function(){window.open('http://v.t.sina.com.cn/share/share.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&source=bookmark','_blank','width=450,height=400');})()"
                    	 title="新浪微博分享">
              					<img src="<?php bloginfo('template_url');?>/images/xinlang.jpg" /></a></li>
                        <li class="lilink" >
                       		<a href="javascript:(function(){window.open('http://v.t.sina.com.cn/share/share.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&source=bookmark','_blank','width=450,height=400');})()"
                        	title="新浪微博分享">新浪微博</a>
                        	</li>
                    </ul>
                    <ul>
                    	<li>
                    	<a href="javascript:(function(){window.open('http://v.t.qq.com/share/share.php??title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&source=bookmark&content=','_blank','width=450,height=400');})()"
                    	 title="腾讯微博分享"><img src="<?php bloginfo('template_url');?>/images/tengxun.jpg" /></a></li>
                        <li class="lilink" >
                       <!-- <a href="#">腾讯微博</a> -->
                       <a href="javascript:(function(){window.open('http://v.t.qq.com/share/share.php??title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&source=bookmark&content=','_blank','width=450,height=400');})()"
                        	 title="腾讯微博分享">腾讯微博</a> 
                        </li>
                    </ul>
                    <ul>
                    	<li><a href="javascript:(function(){window.open('http://www.kaixin001.com/repaste/share.php?rtitle='+encodeURIComponent(document.title)+'&rurl='+encodeURIComponent(location.href)+'&source=bookmark&rcontent=','_blank','width=450,height=400');})()"
                    	 title="开心网分享" >
                    	<img src="<?php bloginfo('template_url');?>/images/kaixin.jpg" /></a></li>
                        <li class="lilink">
                        
                         <a href="javascript:(function(){window.open('http://www.kaixin001.com/repaste/share.php?rtitle='+encodeURIComponent(document.title)+'&rurl='+encodeURIComponent(location.href)+'&source=bookmark&rcontent=','_blank','width=450,height=400');})()"
                        	 title="开心网分享">开心网</a> 
                        </li>
                    </ul>
                    <ul>
                    	<li><a href="javascript:(function(){window.open('http://share.renren.com/share/buttonshare.do?title='+encodeURIComponent(document.title)+'&link='+encodeURIComponent(location.href)+'&source=bookmark&content=','_blank','width=450,height=400');})()"
                    	 title="人人网分享">
                    	<img src="<?php bloginfo('template_url');?>/images/renren.jpg" /></a></li>
                        <li class="lilink"><!-- <a href="#">人人网</a></li> -->
                        <a href="javascript:(function(){window.open('http://share.renren.com/share/buttonshare.do?title='+encodeURIComponent(document.title)+'&link='+encodeURIComponent(location.href)+'&source=bookmark&content=','_blank','width=450,height=400');})()"
                        	title="人人网分享">人人网</a>
                    </ul>
                </div>
            </div>
        
			
			<?php	comments_template("/comment.php"); ?> 
			
		</div>
		<div id="list_right">
				<h2>你可能喜欢？</h2>
				<?php 
					$hotposts = getRelevancePosts($post->ID,10); 
					//$hotposts = $wpdb->get_results($hotPostQue);
					$havePost = false ;
					foreach($hotposts as $hotpost) {
						$havePost = true ;
						//$gameSize = get_post_meta($hotpost->ID, 'GameSize', true);  
						//$gamePic = get_post_meta($hotpost->ID, 'GamePic', true);  
						$gamePic = $hotpost->post_game_image;
						//$gameLink = get_post_meta($hotpost->ID, 'GameLink', true);  
						$postLink = get_permalink($hotpost->ID);
				?>
						<!-- add by shiwei 2011-12-07 delay img print -->
						<?php 
							$delayImgId= "delayIdImg".$hotpost->ID ;
							$loadUrl = $siteurl."/images/load.gif";
						?>
						<script type="text/javascript"> 
						delayImagPrint.put("<?php echo $delayImgId;?>","<?php echo $gamePic;?>") ;
						</script>
						<!-- add end by shiwei -->
						<div class="list_tuijian">
							<span class="list_img" style="text-align: center;"><a href="<?php echo $postLink; ?>">
							<img id="<?php echo $delayImgId;?>" src="<?php echo $loadUrl; ?>" onerror="this.src=<?php echo $siteurl?>/images/onerror.jpg" 
							width="50" height="50" alt="<?php echo $hotpost->post_title;  ?>"  title="<?php echo $hotpost->post_title;?>"
							style="padding-top: 12px;" /></a></span>
							
							<h5 class="listriht listriht_tit"><a href="<?php echo $postLink; ?>"><?php echo $hotpost->post_title;  ?></a></h5>
							<span class="listriht listriht_cat "><?php echo get_cat_name($hotpost->term_id);?></span>
						</div>
				<?php 
					}
					if(!$havePost){
				?>
						<div >没有找到相关的游戏 </div>
				<?php 
					}
				?>
			</div>
			
			
		<?php get_footer();?>